package cn.edu.scau.cmi.wangmaoren.client.classicsDesignPattern;

import af.javafx.layout.AfLinearLayout;
import cn.edu.scau.cmi.wangmaoren.interProgramming.GraduateStudent;
import cn.edu.scau.cmi.wangmaoren.interProgramming.Student;
import cn.edu.scau.cmi.wangmaoren.interProgramming.UndergraduateStudent;
import javafx.application.Application;
import javafx.geometry.Orientation;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.text.Font;
import javafx.stage.Stage;

public class InterProgrammingClient extends Application
{
	private AfLinearLayout root = new AfLinearLayout();
	private AfLinearLayout line = new AfLinearLayout();
	private Button graduateStudentButton = new Button("GraduateStudent");
	private Button undergraduateStudentButton = new Button("UndergraduateStudent");
	private Label blankLeft = new Label();
	private Label blankRight = new Label();
	private TextArea inforText = new TextArea();

	@Override
	public void start(Stage primaryStage)
	{
		try
		{
			initLayout();// 初始化界面

			Scene scene = new Scene(root, 750, 463);
			primaryStage.setTitle("接口编程");
			primaryStage.setScene(scene);
			primaryStage.show();

		} catch (Exception e)
		{
			e.printStackTrace();
		}
	}

	public static void main(String[] args)
	{
		launch(args);
	}

	public void openWindow()
	{
		initLayout();// 初始化界面

		Scene scene = new Scene(root, 750, 463);
		Stage stage = new Stage();
		stage.setTitle("接口编程");
		stage.setScene(scene);
		stage.show();
	}

	private void graduateStudentInfor()
	{
		Student graduateStudent = new GraduateStudent();
		graduateStudent.learning();

		inforText.appendText("\n           " + graduateStudent.learning() + "\n");

	}

	private void underGraduateStudentInfor()
	{
		Student undergraduateStudent = new UndergraduateStudent();
		undergraduateStudent.learning();

		inforText.appendText("\n           " + undergraduateStudent.learning() + "\n");
	}

	/*
	 * 初始化界面
	 */
	private void initLayout()
	{
		root.orientation(Orientation.VERTICAL).spacing(20).padding(20);
		line.spacing(20);

		line.getChildren().addAll(blankLeft, graduateStudentButton, undergraduateStudentButton, blankRight);
		line.layout("1 300px 300px 1");
		root.add(line, "50px");
		root.add(inforText, "1");

		graduateStudentButton.setFont(Font.font("华文中宋", 20));
		undergraduateStudentButton.setFont(Font.font("华文中宋", 20));
		inforText.setFont(Font.font("华文中宋", 18));

		graduateStudentButton.setOnAction((e) -> {
			graduateStudentInfor();
		});
		undergraduateStudentButton.setOnAction((e) -> {
			underGraduateStudentInfor();
		});

	}
}
